package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理相关接口")
@RequestMapping("/admin/order")
@RestController("adminOrderController")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单分页查询
     * @param ordersPageQueryDTO 分页查询参数
     * @return 分页查询结果
     */
    @ApiOperation(value = "订单分页查询")
    @GetMapping("/conditionSearch")
    public Result<PageResult> getOrderPage(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单分页查询：{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.getOrderPage(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id获取订单详情
     * @param id 订单id
     * @return 订单详情
     */
    @ApiOperation(value = "根据id获取订单详情")
    @ApiImplicitParam(name = "id", value = "订单id", required = true, paramType = "path", dataType = "long")
    @GetMapping("/details/{id}")
    public Result<Orders> getOrderById(@PathVariable Long id) {
        log.info("根据id获取订单详情：{}", id);
        return Result.success(orderService.getOrderById(id));
    }


    /**
     * 取消订单
     * @param ordersCancelDTO 取消订单参数
     */
    @ApiOperation(value = "取消订单")
    @PutMapping("/cancel")
    public Result<String> cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单：{}", ordersCancelDTO);
        orderService.cancelOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 接单
     * @param ordersConfirmDTO 接单参数
     */
    @ApiOperation(value = "接单")
    @PutMapping("/confirm")
    public Result<String> confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("接单：{}", ordersConfirmDTO);
        orderService.confirmOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 拒单
     * @param ordersRejectionDTO 拒单参数
     */
    @ApiOperation(value = "拒单")
    @PutMapping("/rejection")
    public Result<String> rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("拒单：{}", ordersRejectionDTO);
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 派单
     * @param id 订单id
     */
    @ApiOperation(value = "派单")
    @ApiImplicitParam(name = "id", value = "订单id", required = true, paramType = "path", dataType = "long")
    @PutMapping("/delivery/{id}")
    public Result<String> deliveryOrder(@PathVariable Long id) {
        log.info("派单：{}", id);
        orderService.deliveryOrder(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id 订单id
     */
    @ApiOperation(value = "完成订单")
    @ApiImplicitParam(name = "id", value = "订单id", required = true, paramType = "path", dataType = "long")
    @PutMapping("/complete/{id}")
    public Result<String> completeOrder(@PathVariable Long id) {
        log.info("完成订单：{}", id);
        orderService.completeOrder(id);
        return Result.success();
    }

    /**
     * 查询订单状态数量统计
     * @return 订单状态数量
     */
    @ApiOperation(value = "查询订单状态数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> getOrderStatistics() {
        log.info("查询订单状态数量统计");
        return Result.success(orderService.getOrderStatistics());
    }

}
